﻿$().ready(function () {
    var seriesCourseID = $("#courseID").val();
    var filter = $("#questions-selected-isanswered").val();
    var sectionID = $("#questions-selected-section").val();

    function getQuestions(sectionID, filter) {
        $.post("/course/questions", { seriesCourseID: seriesCourseID, sectionID: sectionID, filter: filter, viewName: "SeriesCourseQuestionList" }, function (data) {
            $("#tag-question-list").html(data);
        })
    }

    function getQuestion(seriseCourseID) {
        $.get("/seriescourses/question?courseID=" + seriseCourseID, function (data) {
            $("#question-list").html(data);
            $("#question-list").css("display", "block");
            $("#question-ask").css("display", "none");
            $(".question-tagItem").click(function () {
                filter = $(this).attr("questionFilter");

                $(".question-tagItem-selected").attr("class", "question-tagItem");
                $(this).attr("class", "question-tagItem-selected");

                getQuestions(sectionID, filter);
            });


            $("#section-select").change(function () {
                sectionID = $(this).find('option:selected').attr("sectionid");

                getQuestions(sectionID, filter);
            });


            getQuestions(sectionID, filter);

        });
    }

    function getQuestionDetail(questionID) {
        $.post("/course/question", { questionID: questionID, viewName: "SeriesCourseQuestionDetail" }, function (data) {
            $("#question-list").html(data);


        })
    }

    $("#question-detail-asksubmit").click(function () {
        var temp = encodeURIComponent($("#question-detail-asktext").val());
        $("#dfsa").val(temp);
        $("#questionDetailForm").submit();
    });


    getQuestions(sectionID, filter);


    $(".question-tagItem").click(function () {
        filter = $(this).attr("questionFilter");

        $(".question-tagItem-selected").attr("class", "question-tagItem");
        $(this).attr("class", "question-tagItem-selected");

        getQuestions(sectionID, filter);
    });

    $(".questions-list-item").click(function () {
        var questionID = $(this).attr("questionID");
        getQuestionDetail(questionID);
    });

    $("#section-select").change(function () {
        sectionID = $(this).find('option:selected').attr("sectionid");

        getQuestions(sectionID, filter);
    });


    $("#videoSelect").click(function () {
        $("#videoSelect")[0].className = "detailContentLeft-video-tagSelect";
        $("#questionSelect")[0].className = "detailContentLeft-question-tag";
        $("#detail-resource-tab")[0].className = "detailContentLeft-question-tag";

        $("#detailContentLeft-video-list").css("display", "block");
        $("#detailContentLeft-question-list").css("display", "none");
    });

    $("#questionSelect").click(function () {
        $("#videoSelect")[0].className = "detailContentLeft-video-tag";
        $("#questionSelect")[0].className = "detailContentLeft-question-tagSelect";
        $("#detail-resource-tab")[0].className = "detailContentLeft-question-tag";

        $("#detailContentLeft-video-list").css("display", "none");
        $("#detailContentLeft-question-list").css("display", "block");

        //getQuestions(sectionID, filter);
    });

    $("#detail-resource-tab").click(function () {
        $("#videoSelect")[0].className = "detailContentLeft-video-tag";
        $("#questionSelect")[0].className = "detailContentLeft-question-tag";
        $("#detail-resource-tab")[0].className = "detailContentLeft-question-tagSelect";

        $("#detailContentLeft-video-list").css("display", "none");
        $("#detailContentLeft-question-list").css("display", "none");
        //getQuestions(sectionID, filter);
    });


    $("#ask-question-submit").click(function () {
        $("#ask-question-warning").hide();
        if ($("#ask-question-input").val() == 0) {
            $("#ask-question-warning").show();
            return;
        }
        var selectEle = document.getElementById("course-section-select");
        var sectionID = $(selectEle.selectedOptions[0]).attr("sectionid");
        $("#questionContents").val(encodeURIComponent($("#ask-question-input").val()));
        $("#sectionID").val(sectionID);
        $("#askQuestionForm").submit();
    });

});